#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H

#include "taskrecord.h"

#include <QFile>
#include <QObject>
#include <QQueue>
#include <QTime>
#include <QUrl>
#include <QNetworkAccessManager>

class DownloadManager: public QObject
{
    Q_OBJECT

public:
    DownloadManager(QObject *parent = 0);

    void append(TaskRecord* task);
    void append(const QList<TaskRecord*> &taskList);
    QString saveFileName(const TaskRecord &url);

signals:
    void finished();

private slots:
    void startNextDownload();
    void downloadFinished();
    void downloadReadyRead();

private:
    QNetworkAccessManager manager;
    QList<TaskRecord*> downloadQueue;
    QNetworkReply *currentDownload;
    QFile output;
    QTime downloadTime;
    TaskRecord* currentTask;

    int downloadedCount;
    int totalCount;
};

#endif
